import {toast, print} from 'nc-lightapp-front';

export default function tempPrint() {
    const {tabKey, json} = this.state;
    if (tabKey === 'contract') {
        let oids = this.props.table.getCheckedRows('contractList')
            .map(item => item.data.values.pk_psndoc_sub.value);
        if (!oids.length) {
            oids = [this.props.table.getClickRowIndex('contractList').record.pk_psndoc_sub.value];
        }
        print(
            'pdf',
            // 修改url
            '/nccloud/hrcm/account/ContractBatchPrintAction.do',
            {
                funcode: '60110301',
                nodekey: '6011center',
                oids
            }
        );
    } else {
        let rows = this.props.table.getCheckedRows('agreementList'), type = '', oids = [];
        if (!rows.length) {
            rows = [this.props.table.getClickRowIndex('agreementList')];
            type = rows[0].record.agreementtype.value;
            oids = [rows[0].record.pk_agreement.value]
        } else {
            type = rows[0].data.values.agreementtype.value;
            const flag = rows.findIndex(row => row.data.values.agreementtype.value !== type);
            if (flag > -1) {
                toast({color: 'danger', content: json['cm6011-000105']});
                return;
            }
            oids = rows.map(item => item.data.values.pk_agreement.value);
        }
        print(
            'pdf',
            // 修改url
            '/nccloud/hrcm/account/AgreementBatchPrintAction.do',
            {
                funcode: '60110315',
                nodekey: type,
                oids
            }
        );
    }
}
